package demo.controller;

import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import util.JacksonUtil;

@RestController
public class ParamsController {
	
	@RequestMapping({"/params"})
	public Map<String,Object> params(HttpServletRequest request)throws Exception{
		Map<String,Object> map = new LinkedHashMap<>();
		Enumeration<String> headerNames = request.getHeaderNames();
		// map.put("headerNames", headerNames);
		
		if(headerNames!=null) {
			Map<String,Object> headMap = new LinkedHashMap<>();

			while(headerNames.hasMoreElements()) {
				String headerName = headerNames.nextElement();
				headMap.put(headerName, request.getHeader(headerName));
			}
			
			map.put("headerNames",headMap.keySet());
			map.put("headMap",headMap);

		}
		
		
		Map<String, String[]> parameterMap = request.getParameterMap();
		 
		map.put("parameterMap",parameterMap);
		
		String json = request.getParameter("json");
		
		if(json!=null) {			
			Map jsonobj = JacksonUtil.toObject(json, Map.class);
			map.put("jsonobj",jsonobj);
		}

		
		
		return map;
	}
	
	
		
}